//implementation of the geffe generator
//this version uses 32-bit shift register 
#include "geffe.h"

//generate one bit of keystream
int Geffe::generateKeyStream(){
  int a=lfsr1.clock();
  int b=lfsr2.clock();
  int c=lfsr3.clock();
  if(b==0)
    return c;
  else
    return a;
}

//generate 32 bit of keystream
word32 Geffe::generateKeyStream32(){
  //use the following formula
  //algebraic normal form
  //z=x3+x3x2+x1x2
  word32 seq1=lfsr1.clock32();
  word32 seq2=lfsr2.clock32();
  word32 seq3=lfsr3.clock32();
  word32 keyStream(seq3);
  seq3.andOp(seq2);
  seq1.andOp(seq2);
  keyStream.xorOp(seq3);
  keyStream.xorOp(seq1);
  return keyStream;
}
